package priv.yiyuan.example.design.adapter.impl;

import priv.yiyuan.example.design.adapter.MediaPlayer;
import priv.yiyuan.example.design.adapter.Mp4Player;
import priv.yiyuan.example.design.adapter.VlcPlayer;

/**
 * 适配器
 *
 * @author YiYuan
 * @data 2025/8/5
 * @apoNote
 */
public class MediaAdapter implements MediaPlayer {

    /**
     * 持有被适配者对象的引用
     */
    private Mp4Player mp4Player;

    /**
     * 持有被适配者对象的引用
     */
    private VlcPlayer vlcPlayer;

    /**
     * 构造函数，根据媒体类型初始化响应的播放器
     *
     * @param audioType 媒体类型
     */
    public MediaAdapter(String audioType) {

        if (audioType.equalsIgnoreCase("mp4")) {
            mp4Player = new Mp4Player();
        }
        else if (audioType.equalsIgnoreCase("vlc")) {
            vlcPlayer = new VlcPlayer();
        }

    }

    @Override
    public void play(String audioType, String fileName) {

        // 根据媒体类型，调用相应被适配者的播放方法
        if (audioType.equalsIgnoreCase("mp4")) {
            mp4Player.playMp4(fileName);
        }
        else if (audioType.equalsIgnoreCase("vlc")) {
            vlcPlayer.playVlc(fileName);
        }
        else {
            System.out.println("Invalid media. " + audioType + " format not supported");
        }

    }

}
